<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">老师姓名</label>
        <el-input v-model.trim="query.authorName" clearable placeholder="老师姓名" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">老师电话</label>
        <el-input v-model.trim="query.authorPhone" clearable placeholder="老师电话" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">提现状态</label>
        <!--        <el-input v-model="query.isWithdraw" clearable placeholder=" 是否已提现" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />-->
        <el-select
          v-model="query.isWithdraw"
          clearable
          size="small"
          placeholder="提现状态"
          class="filter-item"
          style="width: 180px"
          @change="crud.toQuery"
        >
          <el-option
            v-for="item in dict.fin_withdraw_withdraw"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <label class="el-form-item-label">审核状态</label>
        <!--        <el-input v-model="isReview" clearable placeholder="审核状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />-->
        <el-select
          v-model="query.isReview"
          clearable
          size="small"
          placeholder="是否已审核"
          class="filter-item"
          style="width: 180px"
          @change="crud.toQuery"
        >
          <el-option
            v-for="item in dict.fin_withdraw_review"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="800px">
        <el-form ref="form" :model="form" :inline="true" :rules="rules" size="small" label-width="120px">
          <el-form-item v-if="false" label="编号">
            <el-input v-model.trim="form.id" style="width: 240px;" disabled />
          </el-form-item>
          <el-form-item label="老师姓名">
            <el-input v-model.trim="form.authorName" style="width: 240px;" disabled />
          </el-form-item>
          <el-form-item label="老师电话">
            <el-input v-model.trim="form.authorPhone" style="width: 240px;" disabled />
          </el-form-item>
          <el-form-item label="打赏金额(元)">
            <el-input v-model="form.amount" type="number" style="width: 240px;" disabled />
          </el-form-item>
          <!--          <el-form-item label="分配比例">-->
          <!--            <el-input v-model="form.percent" type="number" style="width: 240px;" :disabled="form.isWithdraw=='0'?false:true" />-->
          <!--          </el-form-item>-->
          <el-form-item label="待提现金额(元)">
            <el-input v-model="form.totalMoney" type="number" style="width: 240px;" disabled />
          </el-form-item>
          <el-form-item label="平台收益(元)">
            <el-input v-model="form.platformMoney" type="number" style="width: 240px;" disabled />
          </el-form-item>
          <el-form-item label="创建时间">
            <el-date-picker v-model="form.createTime" type="datetime" style="width: 240px;" disabled />
          </el-form-item>
          <el-form-item label="提现时间">
            <el-date-picker v-model="form.withdrawTime" type="datetime" style="width: 240px;" disabled />
          </el-form-item>
          <el-form-item label="打赏原由">
            <el-input v-model.trim="form.proName" style="width: 240px;" disabled />
          </el-form-item>
          <el-form-item label="内容id">
            <el-input v-model.trim="form.contentId" style="width: 240px;"disabled />
          </el-form-item>
          <el-form-item label=" 提现状态">
            <el-select v-model="form.isWithdraw" filterable placeholder="请选择" style="width: 240px;" disabled>
              <el-option
                v-for="item in dict.fin_withdraw_withdraw"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="审核状态">
            <el-select v-model="form.isReview" filterable placeholder="请选择" style="width: 240px;" disabled>
              <el-option
                v-for="item in dict.fin_withdraw_review"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <!-- <el-table-column prop="id" label="编号" /> -->
        <el-table-column prop="authorName" label="老师姓名" align="center" />
        <el-table-column prop="authorPhone" label="老师电话" width="95" align="center" />
        <el-table-column prop="amount" label="打赏金额(元)" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.amount/100 }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="totalMoney" label="待提现金额(元)" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.totalMoney/100 }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="platformMoney" label="平台收益(元)" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.platformMoney/100 }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间"align="center">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="withdrawTime" label="提现时间"align="center">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.withdrawTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="proName" label="打赏类型" align="center" />
        <!-- <el-table-column prop="contentId" label="内容id" align="center" /> -->
        <!--        <el-table-column prop="remark" label="备注" align="center" />-->
        <el-table-column prop="isReview" label="审核状态" align="center">
          <template slot-scope="scope">
            {{ dict.label.fin_withdraw_review[scope.row.isReview] }}
          </template>
        </el-table-column>
        <el-table-column prop="isWithdraw" label=" 提现状态" align="center">
          <template slot-scope="scope">
            {{ dict.label.fin_withdraw_withdraw[scope.row.isWithdraw] }}
          </template>
        </el-table-column>
        <el-table-column v-permission="['admin','integral:edit','integral:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <el-button type="warning" :disabled="scope.row.isReview===1" @click="update(scope.row,1)">审核</el-button>
            <el-button type="primary" :disabled="scope.row.isWithdraw===1" @click="update(scope.row,2)">放款</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudWithdraw from '@/api/integral/withdraw'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import { Notification } from 'element-ui'

const defaultForm = { id: null, customerId: null, authorName: null, authorPhone: null, amount: null, totalMoney: null, platformMoney: null, isWithdraw: null, createTime: null, withdrawTime: null, proName: null, contentId: null, percent: null, remark: null, isReview: null }
export default {
  name: 'Withdraw',
  components: { pagination, crudOperation, rrOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['fin_withdraw_withdraw', 'fin_withdraw_review'],
  cruds() {
    return CRUD({ title: '打赏提现', url: 'api/withdraw', idField: 'id', sort: 'id,desc', crudMethod: { ...crudWithdraw },
      optShow: {
        add: false,
        edit: false,
        del: false,
        download: true,
        reset: true
      }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'withdraw:add'],
        edit: ['admin', 'withdraw:edit'],
        del: ['admin', 'withdraw:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'authorName', display_name: '老师姓名' },
        { key: 'authorPhone', display_name: '老师电话' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    [CRUD.HOOK.afterToCU](crud, form) {
      // form.isReview = form.isReview.toString()
      // form.isWithdraw = form.isWithdraw.toString()
      // this.form.amount = form.amount/100
      // this.form.totalMoney = form.totalMoney/100
      // this.form.platformMoney = form.platformMoney/100

    },
    [CRUD.HOOK.beforeToEdit](a, b) {
      b.isReview = b.isReview + ''
      b.isWithdraw = b.isWithdraw + ''
      return true
    },
    update(b, isReview) {
      // const user = this.$store.getters.user
      // param.buyId = user.id
      // param.buyName = user.username
      const param = {}
      if (isReview === 1) {
        param.isReview = 1
      } else {
        param.isWithdraw = 1
      }
      param.id = b.id

      // console.log('++++', this.crud)
      crudWithdraw.edit(param).then(res => {
        Notification.warning(isReview === 1 ? '审核成功' : '放款成功')
        this.crud.refresh()
      })
    }
  }
}
</script>

<style scoped lang="scss">
  .head-container {
    /** 去除input输入框样式 */
    ::v-deep  input[type=number]::-webkit-inner-spin-button {
      -webkit-appearance: none;
    }
	::v-deep input[type="number"]{
	    -moz-appearance:textfield;
	}
  }
</style>
